package basic.study.algorithms.struct;

import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import java.util.ArrayDeque;

/**
 * @author Kevin
 * @date 2020/2/26 19:17
 */
public class CircularQueue {
    private int n;//容量
    private String[] nums;//数组
    private int head = 0;//头
    private int tail = 0;//尾

    public CircularQueue(int cap) {

        n = cap;
        nums = new String[cap];
    }
    //入队
    public boolean enqueue(String val) {
        if ((tail+1) % n  == head) return false;
        nums[tail] = val;
        tail = (tail + 1) % n;
        return true;
    }
    //出队
    public String dequeue() {
        if (head == tail) return null;
        String val = nums[head];
        head = (head + 1) % n;
        return val;
    }
}
